*********************************************************************************
*                                                                               *
*                Election Frequency - Preparing the Dataset     	            *
*                                                                               *
*                           Adding controls                                     *
*                                                                               *
*********************************************************************************



global beg_path `"C:\Users\JohnSmith\Dropbox\Replication_EF\"'  
 
cd `"${beg_path}Data\Analysis 1\"'

use electionsdata_2.dta, clear

*** Encoding country
encode Country, gen(country)
drop Country
rename country Country 
order Country, before(ID)

*** Adding data from CEE 
append using  electionsdata_CEE_2.dta
label define Country 1 "Denmark" 2 "Spain" 3 "Finland" 4"France" 5 "Greece" 6"Ireland" 7"Iceland" 8"Malta" 9"Netherlands" 10"Norway" 11"Portugal" 12"Sweden" ///
 21 "Bulgaria" 22 "Czech Republic" 23  "Estonia" 24  "Hungary" 25  "Latvia" 26  "Lithuania" 27 "Poland" 28  "Romania" 29  "Slovakia" 30 "Slovenia", modify
label values Country Country

*** Generate a dummy for legislative elections 
gen legislative = Type ==2 

*Variable to identify legislative elections that were held in the same year
sort Country legislative Year Round date
quietly by Country legislative Year Round:  gen dup = cond(_N==1,0,_n)
replace dup = . if Type !=2 
fre dup 

list Country legislative Year Round date Date if dup>0 & dup!=.

merge m:1 Country Year using `"${beg_path}Data\Analysis 1\Control Variables\VOD_to_merge.dta"'
drop if _merge ==2
drop _merge
merge m:1 Country Year legislative dup using `"${beg_path}Data\Analysis 1\Control Variables\MP_to_merge.dta"'
drop if _merge ==2
drop _merge

save electionsdata_3.dta, replace


